package com.yl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

/**
 * 获取到配置文件并解析,都是固定代码,copy即可
* @author liuxb 
* @version 1.0  
* @date 2021年10月16日 下午7:05:49
 */
public class Main {
	/**
	 * mybatis-generator配置文件
	*/
	private static final String GENERATOR_CONFIG = "generatorConfig.xml";
//	private static final String GENERATOR_CONFIG = "generatorConfig-mbg.xml";

	public static void main(String[] args) throws Exception{
		List<String> warings = new ArrayList<>();
		boolean overwrite = true;
		File configFile = new File(Thread.currentThread().getContextClassLoader().getResource(GENERATOR_CONFIG).getFile());
		
		ConfigurationParser configurationParser = new ConfigurationParser(warings);
		Configuration configuration = configurationParser.parseConfiguration(configFile);
		DefaultShellCallback callback = new DefaultShellCallback(overwrite);
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(configuration, callback, warings);
		myBatisGenerator.generate(null);
	}
}